package com.shop.milk_tea_shop.controller;

import com.shop.milk_tea_shop.common.CodeEnum;
import com.shop.milk_tea_shop.common.GlobalInfo;
import com.shop.milk_tea_shop.common.Result;
import com.shop.milk_tea_shop.dto.OrderDetailDTO;
import com.shop.milk_tea_shop.request.OrderAddRequest;
import com.shop.milk_tea_shop.request.OrderQueryRequest;
import com.shop.milk_tea_shop.service.OrderDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yjw
 * @since 2024-06-16
 */
@RestController
@RequestMapping("/orderDetail")
public class OrderDetailController {

    @Autowired
    private OrderDetailService orderDetailService;

    @PostMapping("/addOrder")
    public Result<OrderDetailDTO> order(OrderAddRequest request) {
        OrderDetailDTO order = orderDetailService.order(request);
        return new Result<>(CodeEnum.SUCCESS.getMsg(), CodeEnum.SUCCESS, order, new GlobalInfo());
    }

    @GetMapping("/{orderId}")
    public Result<OrderDetailDTO> getOrderById(@PathVariable String orderId) {
        OrderDetailDTO order = orderDetailService.getOrderById(orderId);
        return new Result<>(CodeEnum.SUCCESS.getMsg(), CodeEnum.SUCCESS, order, new GlobalInfo());
    }

    @PostMapping("/paged")
    public Result<List<OrderDetailDTO>> getPagedOrderList(OrderQueryRequest request) {
        return orderDetailService.paged(request);
    }

    @PutMapping
    public Result<Boolean> updateOrder() {
        //TODO 积分+
        return null;
    }
}
